<?php
// error_reporting(E_ALL);

// ID: $Id: $

/**
 * User Class.
 *
 *  Dump
 *  ID()
 *  Email()
 *  Username()
 *  FirstName()
 *  LastName()
 *  IsAnonymous()
 *  LocalEmployer()
 *  LocalAddress()
 *  Phone()
 *  IsLocalEmployee()
 *  IsLocalBusinessOwner()
 *  ResidenceType()
 *  IsLocalStudent()
 *  BusinessName()
 *  BusinessAddress()
 *  BusinessPhone()
 *  ValidateEmailPassword($email, $pwd)
 */

define('USER_ANONYMOUS',     'NONNYMOUSE');

class User
{
    private $_user_rec;

    /**
     * Class Initializer
     *
     */

    function __construct($id = 0)
    {
        global $context;
        global $db;

        if($id > 0) {
            $sql = "SELECT 
                        firstname,
                        lastname,
                        phone,
                        street_address,
                        city_state_zip,
                        business_name,
                        business_address,
                        business_city_state_zip,
                        residence_status,
                        is_business_owner,
                        status
                    FROM onebainb_nv.users
                    WHERE id = {$id}";
            $this->_user_rec = $db->SqlOneObject($sql);
        }
    }

    public function Dump()
    {
        var_dump($this->_user_rec);
    }

    private function ID() 
    {
        global $context;
        return $context->SessionUserID();
    }

    public function IsLoggedIn() {
        return isset($this->_user_rec);
    }

    public function Email() {
        return $this->user_rec->email ;
    }

    public function FullName() {
        if($this->IsAnonymous()) {
            return "I M Anonymous";
        }
        else {
            return $this->FirstName() . " " . $this->LastName();
        }
    }

    public function FirstName()
    {
        if($this->IsAnonymous())
        {
            return "I M";
        }
        else
        {
            return $this->_user_rec->firstname;
        }
    }

    public function LastName()
    {
        if($this->IsAnonymous())
        {
            return "Anonymous";
        }
        else
        {
            return $this->_user_rec->lastname;
        }
    }

    public function IsAnonymous()
    {
        return empty($this->_user_rec);
    }
}

